// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'

axios.interceptors.request.use(function(config) {

  //我们统一给 请求添加token令牌
  const token = sessionStorage.getItem("token")
  if (token) {
      config.headers.Authorization = 'JWT ' + token
  }

  return config

}, function(error) {
  return Promise.reject(error) //直接抛出
})
axios.interceptors.response.use(function(resp) {

  //我们统一给 请求添加token令牌
    return resp
},function(error) {
    if(error.response.status==401){
      alert('您还没有登录，没有权限做这个事情')
      router.push({'path':'/login'})
    }else{
      return Promise.reject(error)
    }
})


axios.defaults.baseURL='http://127.0.0.1:8000/'

Vue.prototype.axios=axios

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
